﻿using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.App.UI.Accounting
{
    /// <summary>
    /// Interaction logic for SellerMoneyUserControl.xaml
    /// </summary>
    public partial class SellerMoneyUserControl : UserControl, IPlugin
    {
        private SellerMoneyService sellerMoneyService = ServiceContainer.GetService<SellerMoneyService>();

        public SellerMoneyUserControl()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            float moneyStart = -1;
            float moneyEnd = -1;

            try
            {
                moneyStart = float.Parse(tbStart.Text.Trim());
                moneyEnd = float.Parse(tbEnd.Text.Trim());
            }
            catch
            {
            }

            this.pbBar.Parameters.Clear();
            int sellerId = 0;
            int.TryParse(this.tbSellerId.Text, out sellerId);
            this.pbBar.Parameters.Add("sellerId", sellerId);
            this.pbBar.Parameters.Add("startMoney", moneyStart);
            this.pbBar.Parameters.Add("endMoney", moneyEnd);
            this.pbBar.StartPage();

        }
        private void btnCharge_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                new SellerChargeWindow().ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void pbBar_PageChanging(object sender, PageBar.PageChangeEventArgs e)
        {
            var data = this.sellerMoneyService.GetByAll(e.GetParameter<int>("sellerId"), e.GetParameter<float>("startMoney"), e.GetParameter<float>("endMoney"), e.CurrentPage - 1, e.PageSize);
            this.dgvMoneys.ItemsSource = data.Datas;
            this.pbBar.Total = data.Total;
            this.pbBar.CurrentCount = data.Datas.Count;
            this.tbTotalMoney.Text = "当前页金额:" + data.Datas.Select(obj => obj.Money).Sum().ToString("F2");
        }

        public string Title
        {
            get { return "余额管理"; }
        }

        public Control UIControl
        {
            get { return this; }
        }
    }
}
